home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / util / pack / xpk_Source.lha / xpk_Source / xpkmaster / xpkmaster.h < prev    next >
C/C++ Source or Header  |  1998-03-27  |  10KB  |  271 lines

  1. #ifndef XPKMASTER_XPKMASTER_H
  2. #define XPKMASTER_XPKMASTER_H
  3.  
  4. /* Includeheader
  5.  
  6.     Name:        xpkmaster.h
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: xpkmaster.h 1.13 (21.02.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Master library global definitions and declarations
  12.             and prototypes
  13.  
  14.  1.0   05.10.96 : first real version
  15.  1.1   27.12.96 : removed library protos - call now via library interface,
  16.      allows patching
  17.  1.2   30.01.97 : change of cchecksum proto
  18.  1.3   31.01.97 : checksum changed again
  19.  1.4   01.03.97 : added new flags
  20.  1.5   08.03.97 : changed XpkBuffer a bit
  21.  1.6   31.03.97 : some little corrections
  22.  1.7   02.04.97 : removed obsolete stuff
  23.  1.8   12.04.97 : added DebugTagList
  24.  1.9   14.08.97 : fixed defines
  25.  1.10  20.12.97 : changed a lot in defines and structures
  26.  1.11  09.01.98 : added better key-fields to xbuf
  27.  1.12  24.01.98 : removed PP support --> done by xfdmaster now
  28.  1.13  21.02.98 : added code independence
  29. */
  30.  
  31. /* To disable PowerPacker support comment out the next line. */
  32. /* #define USE_POWERPACKER */
  33.  
  34. #ifdef __SASC
  35.   #define ASM(arg)    arg __asm
  36. #else
  37.   #define ASM(arg)    arg
  38. #endif
  39.  
  40. #ifdef __GNUC__
  41.   #define REG(reg,arg)    arg __asm(#reg)
  42. #else
  43.   #define REG(reg,arg)    register __##reg arg
  44. #endif
  45.  
  46. #ifdef SUPPORT_A4
  47.   #define A4SUPP    ,a4
  48.   #define A4SUPP2    ,xbuf->xb_regA4
  49.   #define A4PROTO    ,REG(a4, ULONG a4)
  50. #else
  51.   #define A4SUPP
  52.   #define A4SUPP2
  53.   #define A4PROTO
  54. #endif
  55.  
  56. #ifndef XPK_ALLINONE /* This allows some optimizations, when All.c is used */
  57.   #define XPK_ALLINONE
  58. #endif
  59.  
  60. #define SDI_TO_ANSI
  61. #include "SDI_ASM_STD_protos.h"
  62.  
  63. #include <xpk/xpk.h>
  64. #include <xpk/xpksub.h>
  65.  
  66. typedef ASM(ULONG) (*regfunc) (REG(a0, struct Hook *),
  67.                    REG(a1, APTR), REG(a2, APTR) A4PROTO);
  68.  
  69. #define ROUNDLONG(x)        (((x)+3)&(~3))    /* round to next longword */
  70. #define DEFAULTCHUNKSIZE    0x8000
  71.  
  72. #ifndef Min
  73.   #define Min(a,b) ((a) < (b) ? (a) : (b))
  74.   #define max(a,b) ((a) > (b) ? (a) : (b))
  75. #endif
  76.  
  77. /* The structure used for I/O, special master library version */
  78. struct XpkMasterMsg {
  79.   ULONG  xmm_Type;        /* Read/Write/Alloc/Free/Abort        */
  80.   STRPTR xmm_Ptr;        /* The mem area to read from/write to    */
  81.   LONG   xmm_Size;        /* The size of the read/write        */
  82.   ULONG  xmm_IOError;        /* The IoErr() that occurred        */
  83.   ULONG  xmm_Reserved;        /* Reserved for future use        */
  84.   STRPTR xmm_Buf;        /* Specific to the internal hooks    */
  85.   LONG   xmm_Error;        /* The XPKERR that occurred        */
  86.   ULONG  xmm_BufLen;
  87.   ULONG  xmm_BufOfs;
  88.   ULONG  xmm_Len;
  89.   ULONG  xmm_Flags;
  90.   ULONG  xmm_FH;
  91.   ULONG  xmm_MemType;
  92.   STRPTR xmm_FileName;
  93. };
  94.  
  95. #define XIO_GETOUTBUF 1        /* flag for xmm_Flags - allocate buffer    */
  96.  
  97. /* These structures define the file format for compressed streams */
  98. struct XpkStreamHeader {
  99.   ULONG xsh_Pack;
  100.   ULONG xsh_CLen;
  101.   ULONG xsh_Type;
  102.   ULONG xsh_ULen;
  103.   UBYTE xsh_Initial[16];
  104.   UBYTE xsh_Flags;
  105.   UBYTE xsh_HChk;
  106.   UBYTE xsh_SubVrs;
  107.   UBYTE xsh_MasVrs;
  108. };
  109.  
  110. #define XPK_COOKIE    0x58504b46    /* 'XPKF' - ID for xsh_Pack */
  111. #define ROW_OF_MINUS    0x2d2d2d2d    /* '----' */
  112. #define PP_COOKIE    0x50503230    /* 'PP20' */
  113. #define XFD_COOKIE    0x58464444    /* 'XFDD' */
  114. #define USER_COOKIE    0x55534552    /* 'USER' */
  115.  
  116. #define XPKSTREAMF_LONGHEADERS  0x01    /* Use XpkLongLocHeaders    */
  117. #define XPKSTREAMF_PASSWORD     0x02    /* This file encoded        */
  118. #define XPKSTREAMF_EXTHEADER    0x04    /* Extended globhdr        */
  119.  
  120. struct XpkChunkHdrWord {
  121.   UBYTE xchw_Type;
  122.   UBYTE xchw_HChk;
  123.   UWORD xchw_CChk;
  124.   UWORD xchw_CLen;
  125.   UWORD xchw_ULen;
  126. };
  127.  
  128. struct XpkChunkHdrLong {
  129.   UBYTE xchl_Type;
  130.   UBYTE xchl_HChk;
  131.   UWORD xchl_CChk;
  132.   ULONG xchl_CLen;
  133.   ULONG xchl_ULen;
  134. };
  135.  
  136. typedef union {
  137.   struct XpkChunkHdrLong xch_Long;
  138.   struct XpkChunkHdrWord xch_Word;
  139. } XpkChunkHeader;
  140.  
  141. #define XPKCHUNK_RAW        0x00 /* raw copy of source */
  142. #define XPKCHUNK_PACKED        0x01 /* packed data */
  143. #define XPKCHUNK_END        0x0F /* empty end Chunk */
  144.  
  145. struct Headers {
  146.   struct XpkStreamHeader h_Glob;
  147.   XpkChunkHeader     h_Loc;
  148.   ULONG             h_LocSize;
  149. };
  150.  
  151. #define XPKMODE_UPUP    1
  152. #define XPKMODE_UPSTD   2
  153. #define XPKMODE_UPPP    3
  154. #define XPKMODE_UPXFD    4
  155. #define XPKMODE_PKSTD  20
  156.  
  157. #define AUTO_PASS_SIZE    50
  158.  
  159. /* This is what XPK "handles" really point to */
  160. struct XpkBuffer {
  161.   struct XpkFib    xb_Fib;        /* file info about this file        */
  162.   UWORD   xb_PackingMode;    /* desired packing efficiency, 0..100   */
  163.   struct Headers xb_Headers;    /* global and local file header     */
  164.   ULONG   xb_Format;        /* type of file                */
  165.   LONG    xb_Result;        /* error code from last call        */
  166.   STRPTR  xb_ErrBuf;        /* Where user wants the error        */
  167.   STRPTR *xb_GetOutBuf;        /* Where user wants the out buf addr    */
  168.   ULONG  *xb_GetOutLen;        /* Where user wants the output len    */
  169.   ULONG  *xb_GetOutBufLen;    /* Where user wants the out buf len    */
  170.   ULONG   xb_Secs;        /* Start time, the seconds        */
  171.   ULONG   xb_Mics;        /* Start time, the micros        */
  172.   struct Hook * xb_RHook;    /* input data hook            */
  173.   struct Hook * xb_WHook;    /* output data hook            */
  174.   struct Hook * xb_ChunkHook;    /* Hook to call between chunks        */
  175.   STRPTR  xb_Password;        /* password for de/encoding        */
  176.   ULONG   xb_PasswordSize;    /* password buffer size for own password*/
  177.   ULONG   xb_PassKey32;        /* password key, 32 bit            */
  178.   UWORD   xb_PassKey16;        /* password key, 16 bit            */
  179.   WORD    xb_Priority;        /* task pri during packing        */
  180.   ULONG   xb_SubID;        /* currently active sub ID        */
  181.   ULONG   xb_ChunkSize;        /* Chunk size to use for packing    */
  182.   ULONG   xb_FirstChunk;    /* First chunk size - largest chunk    */
  183.   ULONG   xb_Flags;        /* private for xpkmaster        */
  184.   LONG    xb_InLen;        /* Number of bytes to (un)pack        */
  185.   STRPTR  xb_LastMsg;        /* The last progress message        */
  186.   struct xfdBufferInfo * xb_xfd;/* xfdBufferInfo            */
  187.   struct XpkInfo * xb_SubInfo;    /* Info of current open sub-lib        */
  188.   struct Library * xb_SubBase;    /* Currently open sub-library        */
  189.   struct XpkMasterMsg xb_RMsg;    /* Parameters for reading        */
  190.   struct XpkMasterMsg xb_WMsg;    /* Parameters for writing        */
  191.   struct XpkSubParams xb_PackParam;/* Parameters to (Un)PackChunk()    */
  192.   struct XpkProgress  xb_Prog;    /* Parameters to progress report    */
  193. #ifdef SUPPORT_A4
  194.   ULONG      xb_regA4;
  195. #endif
  196. };
  197.  
  198. /* Values for MasterFlags */
  199. #define XMF_PRIVFH    (1<< 0)    /* We opened the FH, so we close it.    */
  200. #define XMF_PACKING    (1<< 1)    /* This is a packing operation.        */
  201. #define XMF_PASSTHRU    (1<< 2)    /* Pass uncompressed data through    */
  202. #define XMF_GETOUTBUF    (1<< 3)    /* Get output buffer when size known    */
  203. #define XMF_NOCLOBBER    (1<< 4)    /* Don't overwrite            */
  204. #define XMF_EOF        (1<< 5)    /* End of file                */
  205. #define XMF_INITED    (1<< 6)    /* Sublib buffers have been allocted    */
  206. #define XMF_GLOBHDR    (1<< 7)    /* GlobHdr is already written        */
  207. #define XMF_LOSSYOK    (1<< 8)    /* Lossy compression permitted        */
  208. #define XMF_OWNTASKPRI    (1<< 9) /* Altered task pri, restore        */
  209. #define XMF_NOCRC    (1<<10)    /* Do not check the checksum on decomp    */
  210. #define XMF_NOPREFS    (1<<11) /* Are prefs allowed ?            */
  211. #define XMF_XFD        (1<<12) /* Is XFD unpacking allowed ?        */
  212. #define XMF_EXTERNALS    (1<<13) /* Is extern allowed ?            */
  213. #define XMF_AUTOPASSWD    (1<<14) /* Automatic password            */
  214. #define XMF_AUTOPRHOOK  (1<<15) /* Automatic Progress hook        */
  215. #define XMF_NOPACK    (1<<16) /* destination file equals source    */
  216. #define XMF_OWNPASSWORD (1<<17) /* free password buffer later !!!    */
  217. #define XMF_KEY16    (1<<18) /* got a 16 bit key (needed, as key may */
  218. #define XMF_KEY32    (1<<19) /* got a 32 bit key  be 0 - no check)   */
  219.  
  220. #ifdef DEBUG
  221. void     DebugError(STRPTR, ...);            /* debug.c */
  222. void     DebugRunTime(STRPTR, ...);            /* debug.c */
  223. void    DebugTagList(STRPTR, struct TagItem *);        /* debug.c */
  224. #endif
  225.  
  226. extern struct DosLibrary       *DOSBase;        /* libinit.a */
  227. extern struct Hook        fhinhook;        /* hook_fh.c */
  228. extern struct Hook        fhouthook;        /* hook_fh.c */
  229. extern struct IntuitionBase    *IntuitionBase;        /* libinit.a */
  230. extern struct Hook        meminhook;        /* hook_mem.c */
  231. extern struct Hook        memouthook;        /* hook_mem.c */
  232. extern struct ExecBase         *SysBase;        /* libinit.a */
  233. extern struct UtilityBase      *UtilityBase;        /* libinit.a */
  234. extern struct Library           *XpkBase;        /* libinit.a */
  235.  
  236. XPK_ALLINONE LONG    callprogress(struct XpkBuffer *);            /* progress.c */
  237. XPK_ALLINONE UWORD    cchecksum(ULONG *, ULONG);                /* checksum.c */
  238. XPK_ALLINONE void    closesub(struct XpkBuffer *);                /* sublibs.c */
  239. XPK_ALLINONE LONG    freebufs(struct XpkBuffer *);                /* xbuf.h */
  240. XPK_ALLINONE struct XpkPrefsSemaphore *    GetPrefsSem(void);            /* objects.c */
  241. XPK_ALLINONE UBYTE    hchecksum(STRPTR, ULONG);                /* checksum.c */
  242. XPK_ALLINONE APTR    hookread(struct XpkBuffer *, ULONG, APTR, ULONG);    /* hook.c */
  243. XPK_ALLINONE APTR    hookwrite(struct XpkBuffer *, ULONG, APTR, ULONG);    /* hook.c */
  244. XPK_ALLINONE ULONG    idfromname(STRPTR);                    /* sublibs.c */
  245. XPK_ALLINONE struct XpkBuffer *        initxbuf(void);                /* xbuf.h */
  246. XPK_ALLINONE struct Library *        opensub(struct XpkBuffer *, ULONG);    /* sublibs.c */
  247. XPK_ALLINONE LONG    parsebuftags(struct XpkBuffer*, struct TagItem*);    /* tags.c */
  248. XPK_ALLINONE LONG    parseerrortags(struct TagItem *, LONG);            /* tags.c */
  249. XPK_ALLINONE void    parsegettags(struct XpkBuffer *);            /* tags.c */
  250. XPK_ALLINONE void    percentages(struct XpkFib *);                /* fib.c */
  251. XPK_ALLINONE void    updatefib(struct XpkBuffer *);                /* fib.c */
  252. XPK_ALLINONE ASM(LONG)    xpkopen(REG(a0, struct XpkBuffer **),
  253.             REG(a1, struct TagItem *), REG(d2,ULONG) A4PROTO);    /* open.c */
  254.  
  255. ASM(LONG)  LIBXpkExamine(REG(a0, struct XpkFib *), REG(a1, struct TagItem *) A4PROTO);
  256. ASM(LONG)  LIBXpkPack(REG(a0, struct TagItem *) A4PROTO);
  257. ASM(LONG)  LIBXpkUnpack(REG(a0, struct TagItem *) A4PROTO);
  258. ASM(LONG)  LIBXpkOpen(REG(a0, struct XpkBuffer **), REG(a1, struct TagItem *) A4PROTO);
  259. ASM(LONG)  LIBXpkRead(REG(a0, struct XpkBuffer *), REG(a1, STRPTR), REG(d0, ULONG));
  260. ASM(LONG)  LIBXpkWrite(REG(a0, struct XpkBuffer *), REG(a1, STRPTR), REG(d0, ULONG));
  261. ASM(LONG)  LIBXpkSeek(REG(a0, struct XpkBuffer *), REG(d0, LONG), REG(d1, ULONG));
  262. ASM(LONG)  LIBXpkClose(REG(a0, struct XpkBuffer *));
  263. ASM(LONG)  LIBXpkQuery(REG(a0, struct TagItem *));
  264. ASM(APTR)  LIBXpkAllocObject(REG(d0, ULONG), REG(a0, struct TagItem *));
  265. ASM(void)  LIBXpkFreeObject(REG(d0, ULONG), REG(a0, APTR));
  266. ASM(BOOL)  LIBXpkPrintFault(REG(d0, LONG), REG(a0, STRPTR));
  267. ASM(ULONG) LIBXpkFault(REG(d0, LONG), REG(a0, STRPTR), REG(a1, STRPTR), REG(d1, ULONG));
  268. ASM(LONG)  LIBXpkPassRequest(REG(a0, struct TagItem *));
  269.  
  270. #endif /* XPKMASTER_XPKMASTER_H */
  271.